package com.gmall.console.job;

import com.gmall.console.system.entity.User;
import com.gmall.console.system.service.IUserService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @description: 使用xxl-job
 * @author: Jone
 * @create: 2024-06-16
 */
@Component
public class TestJob {

    @Resource
    private IUserService iUserService;

    @XxlJob("demoJob")
    public void demoJob() throws Exception{
        System.out.println("定时执行任务，执行时间："+new Date());
    }

    @XxlJob("shardingJobHandler")
    public void shardingJobHandler() throws Exception {

        // 分片参数
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

        //查询分片的数据
        List<User> userList = iUserService.getUserList(shardTotal, shardIndex);


    }


}
